import java.util.LinkedList;

public class Main {
    public static void main(String[] args) {
        // 创建一个 LinkedList
        LinkedList<String> linkedList = new LinkedList<>();

        // 添加元素
        linkedList.add("Java");
        linkedList.add("Python");
        linkedList.add("C++");

        // 输出 LinkedList
        System.out.println("LinkedList: " + linkedList);

        // 在第一个位置插入元素
        linkedList.addFirst("JavaScript");
        System.out.println("After addFirst: " + linkedList);

        // 在最后一个位置插入元素
        linkedList.addLast("Ruby");
        System.out.println("After addLast: " + linkedList);

        // 获取并移除第一个元素
        String firstElement = linkedList.removeFirst();
        System.out.println("Removed First Element: " + firstElement);
        System.out.println("After removeFirst: " + linkedList);

        // 获取并移除最后一个元素
        String lastElement = linkedList.removeLast();
        System.out.println("Removed Last Element: " + lastElement);
        System.out.println("After removeLast: " + linkedList);

        // 获取但不移除第一个元素
        String first = linkedList.getFirst();
        System.out.println("First Element: " + first);

        // 获取但不移除最后一个元素
        String last = linkedList.getLast();
        System.out.println("Last Element: " + last);
    }
}